package com.firewolf.oa.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.firewolf.oa.base.impl.BaseServiceImpl;
import com.firewolf.oa.dao.UserDao;
import com.firewolf.oa.entities.User;
import com.firewolf.oa.service.UserService;

@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

	//root用户账号
	@Value("${root.name}")
	private String rootName;
	
	//root用户密码
	@Value("${root.password}")
	private String rootPwd;
	
	//root用户昵称
	@Value("${root.nickName}")
	private String rootNickName;
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public void resetPassword(Long id) {
		User user = userDao.findById(id);
		if(user != null){
			user.setPassword("1234");
			userDao.update(user);
		}
	}

	@Override
	public User findUserByNameAndPwd(String name, String password) {
		if(rootName.equals(name)){
			if(rootPwd.equals(password)){
				User user = new User();
				user.setLoginName(rootName);
				user.setPassword(rootPwd);
				user.setName(rootNickName);
				return user;
			}
			return null;
		}
		return userDao.findUserByNameAndPwd(name,password);
	}

}
